typedef class object;
typedef class bus_item;

class bus_sequence extends object;
	bus_item write_item[];
	bus_item read_item;
	
	extern function new(string name = "");
	extern virtual function void body(); // 虚方法
	extern virtual function void copy(object rhs = null);
	extern virtual function void print(); // 虚方法
endclass

function bus_sequence::new(string name);
	super.new(name);
endfunction

function void bus_sequence::body();
	write_item = new[4];
	foreach(write_item[i]) begin
		write_item[i] = new($sformatf("write_item%0d", i));
		write_item[i].write = 1;
	end
	read_item = new("read_item");
	read_item.write = 0;
endfunction

function void bus_sequence::copy(object rhs);
	super.copy(rhs);
	begin
		bus_sequence rhs_; // 派生类句柄
		if ((rhs == null) || !$cast(rhs_, rhs)) begin // 句柄向下类型转换
			$display("cast fail");
			return;
		end
		foreach(write_item[i]) begin
			write_item[i].copy(rhs_.write_item[i]);
		end
		read_item.copy(rhs_.read_item);
	end
endfunction

function void bus_sequence::print();
	super.print();
	foreach(write_item[i]) begin
		write_item[i].print();
	end
	read_item.print();
endfunction
